package com.kl.drs.util;

import java.io.File;

public class DelFileUtil {
	 public static boolean delFile(String path) {
	       boolean flag = false;
	       File file = new File(path);
	       if (!file.exists()) {
	         return flag;
	       }
	       if (!file.isDirectory()) {
	         return flag;
	       }
	       String[] tempList = file.list();
	       File temp = null;
	       for (int i = 0; i < tempList.length; i++) {
	          if (path.endsWith(File.separator)) {
	             temp = new File(path + tempList[i]);
	          } else {
	              temp = new File(path + File.separator + tempList[i]);
	          }
	          if (temp.isFile()) {
	             temp.delete();
	          }
	          if (temp.isDirectory()) {
	             delFile(path + "/" + tempList[i]);//先删除文件夹里面的文
	             flag = true;
	          }
	       }
	       return flag;
	     }
	 public static boolean deleteOneFile(String fileName) {
	        File file = new File(fileName);
	        // 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
	        if (file.exists() && file.isFile()) {
	            if (file.delete()) {
	                //System.out.println("删除单个文件" + fileName + "成功！");
	            	Log4jUtils.logDebug("删除单个文件" + fileName + "成功！");
	                return true;
	            } else {
	                //System.out.println("删除单个文件" + fileName + "失败！");
	            	Log4jUtils.logDebug("删除单个文件" + fileName + "失败！");
	                return false;
	            }
	        } else {
	            //System.out.println("删除单个文件失败：" + fileName + "不存在！");
	        	Log4jUtils.logDebug("删除单个文件失败：" + fileName + "不存在！");
	            return false;
	        }
	    }
	 
}
